package com.czy.owner.adapter;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.CarBrandModel;
import com.czy.owner.entity.UserLocationModel;
import com.czy.owner.widget.RoundImageView;
import com.easyrecycleview.adapter.BaseViewHolder;
import com.easyrecycleview.adapter.RecyclerArrayAdapter;

import org.xutils.common.Callback;
import org.xutils.x;


/**
 * @author: Raven
 * @date: 2018/2/28 13:37
 * @email: xiexiaomeng_001@163.com
 * @description: 
 */

public class HotCarBrandAdapter extends RecyclerArrayAdapter<CarBrandModel> {
    private Context context;

    public HotCarBrandAdapter(Context context) {
        super(context);
        this.context = context;
    }


    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new HotCarBrandViewHolder(parent);
    }

    class HotCarBrandViewHolder extends BaseViewHolder<CarBrandModel> {
        private TextView tv_item_hot_brand;
        private RoundImageView iv_item_hot_brand;
        private LinearLayout itemRoot;

        public HotCarBrandViewHolder(ViewGroup parent) {
            super(parent, R.layout.item_hot_car_brand);
            tv_item_hot_brand = $(R.id.tv_item_hot_brand);
            iv_item_hot_brand = $(R.id.iv_item_hot_brand);
            itemRoot = $(R.id.item_root);
        }

        @Override
        public void setData(final CarBrandModel data) {
            super.setData(data);

            if (data.getImageSrc() != null && !data.getImageSrc().isEmpty()) {
                iv_item_hot_brand.setTag(data.getImageSrc());
                x.image().bind(iv_item_hot_brand, data.getImageSrc(), new Callback.CommonCallback<Drawable>() {
                    @Override
                    public void onError(Throwable ex, boolean isOnCallback) {
                        iv_item_hot_brand.setImageResource(R.mipmap.default_icon);
                    }

                    @Override
                    public void onFinished() {

                    }

                    @Override
                    public void onCancelled(CancelledException cex) {
                        iv_item_hot_brand.setImageResource(R.mipmap.default_icon);
                    }

                    @Override
                    public void onSuccess(Drawable result) {
                    }
                });
            } else {
                iv_item_hot_brand.setImageResource(R.mipmap.default_icon);
            }

            tv_item_hot_brand.setText(data.getChName());

        }
    }
}
